package com.ruoyi.sl.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlGprocess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sl.mapper.SlProcessMapper;
import com.ruoyi.sl.domain.SlProcess;
import com.ruoyi.sl.service.ISlProcessService;

/**
 * 工序Service业务层处理
 * 
 * @author admin
 * @date 2024-06-03
 */
@Service
public class SlProcessServiceImpl implements ISlProcessService 
{
    @Autowired
    private SlProcessMapper slProcessMapper;

    /**
     * 查询工序
     * 
     * @param processId 工序主键
     * @return 工序
     */
    @Override
    public SlProcess selectSlProcessByProcessId(Long processId)
    {
        return slProcessMapper.selectSlProcessByProcessId(processId);
    }


    /**
     * 校验工序名是否存在
     *
     * @param slProcess 工序信息
     * @return
     */
    @Override
    public Boolean checkProcessName(SlProcess slProcess){
        Long processId = StringUtils.isNull(slProcess.getProcessId()) ? -1L : slProcess.getProcessId();
        SlProcess process = slProcessMapper.selectSlProcessByProcessName(slProcess);
        if (StringUtils.isNotNull(process) && process.getProcessId().longValue() != processId.longValue())
        {
            return false;
        }
        return true;
    }

    /**
     * 查询工序列表
     * 
     * @param slProcess 工序
     * @return 工序
     */
    @Override
    public List<SlProcess> selectSlProcessList(SlProcess slProcess)
    {
        return slProcessMapper.selectSlProcessList(slProcess);
    }

    //根据大工序ID查询所有小工序
    @Override
    public List<SlProcess> selectSlProcessListByGprocessId(Long gprocessId)
    {
        return slProcessMapper.selectSlProcessListByGprocessId(gprocessId);
    }

    /**
     * 新增工序
     * 
     * @param slProcess 工序
     * @return 结果
     */
    @Override
    public int insertSlProcess(SlProcess slProcess)
    {
        slProcess.setCreateTime(DateUtils.getNowDate());
        return slProcessMapper.insertSlProcess(slProcess);
    }

    /**
     * 修改工序
     * 
     * @param slProcess 工序
     * @return 结果
     */
    @Override
    public int updateSlProcess(SlProcess slProcess)
    {
        slProcess.setUpdateTime(DateUtils.getNowDate());
        return slProcessMapper.updateSlProcess(slProcess);
    }

    /**
     * 批量删除工序
     * 
     * @param processIds 需要删除的工序主键
     * @return 结果
     */
    @Override
    public int deleteSlProcessByProcessIds(Long[] processIds)
    {
        return slProcessMapper.deleteSlProcessByProcessIds(processIds);
    }

    /**
     * 删除工序信息
     * 
     * @param processId 工序主键
     * @return 结果
     */
    @Override
    public int deleteSlProcessByProcessId(Long processId)
    {
        return slProcessMapper.deleteSlProcessByProcessId(processId);
    }
}
